/**
 * 判断模块菜单是否有权限
 */
import cacheUtil from '@/utils/cache'

function checkMenu(tree, id) {
  var isGet = false
  var retNode = null

  function deepSearch(tree, id) {
    for (let i = 0; i < tree.length; i++) {
      if (tree[i].children && tree[i].children.length > 0) {
        deepSearch(tree[i].children, id)
      }
      if (id == tree[i].pkid || isGet) {
        isGet || (retNode = tree[i])
        isGet = true
        break
      }
    }
  }
  deepSearch(tree, id)
  return retNode ? retNode.hasPri : false
}
export function checkMenuById(id) {
  const level = cacheUtil.getItem('status') * 1
  // if (level === 3) {
  //   return true
  // } else {
  const tree = JSON.parse(cacheUtil.getItem('menu'))
  return checkMenu(tree, id)
  // }
}

export function checkNavListItem(id) {
  const tree = JSON.parse(cacheUtil.getItem('menu'))
  const navList = tree[0].children || []
  return navList.some((e) => e.hasPri && e.pkid === id)
}
